<?php


  class YueAction extends CommonAction{
  
    public function index(){
	
	
	  if(isset($_GET['keywords'])){
	  
	    $username=$_GET['keywords'];
	  
	    $where['username']=array('LIKE',"%$username%");
		
		$this->keyword=$_GET['keywords'];
	  
	  }
	  
	
	  $where['money']=array('neq','0');
	
	  $re=$this->page('dailiuser','10','id desc',$where);
	
	  $this->re=$re;
	  
	  
	  $w['money']=array('neq','0');
	  
	  $res=M('dailiuser')->where($w)->select();
	  
	  $yue=0;
	  
	  foreach($res as $v){
	  
	    $yue+=$v['money'];
	  
	  }
	  
	  $this->yue=$yue;
	  
	  
	
	  $this->display();
	
	}
	
	
	
	public function save(){
	
	
	    /*vendor('Wxhongbao.hongbao');
        $tixian = M('buyer')->where('id='.$_GET['id'])->find();
	  	$user = M('user')->where("openid='".$tixian['openid']."'")->find();
		
	  	$wx = M('wx')->where('id=2')->find();
	  	header("Content-type: text/html; charset=utf-8");

		//APPID
		define('APPID',$wx['appid']);
		//商户id，10025915
		define('MCHID',$wx['shanghuhao']);
		//微信支付密钥，商户平台中，账户设置->安全设置->API安全->API密钥：api设置
		define('PARTNERKEY',$wx['miyao']);

		//以下接口均已调试成功，需要你自行对接到自己的系统中。
        //dump($tixian['money']);die;

		//企业付款
		$obj1 = array();
		$obj1['openid']         	= $user['openid'];
		$obj1['amount']         	= $tixian['money']*100;
		$obj1['desc']        		= "现金提现付款";
		$obj1['mch_appid']         	= APPID;
		$obj1['mchid']         		= MCHID;
		$obj1['partner_trade_no']	= MCHID.date('YmdHis').rand(1000, 9999);
		$obj1['spbill_create_ip']   = $_SERVER['REMOTE_ADDR'];
		$obj1['check_name']      	= "NO_CHECK";
		

		$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
		$wxHongBaoHelper = new WxPay();
		$result = $wxHongBaoHelper->pay($url, $obj1);
	    $obj =  simplexml_load_string($result, null, LIBXML_NOCDATA); //转换成对象
	   // dump($obj);die;
        $arr  = $obj->result_code;//提取对象中某个属性值
        if($arr=="SUCCESS"){
          $data['status'] = '1';
          M('buyer')->where('id='.$_GET['id'])->save($data);
          $this->success("发放成功！");
        }else{
        	$this->error("发送失败！");
        }
	*/
	
	    $result=M('yanzheng')->where('id=1')->find();
	
	     if($result['yanzheng']!=$_POST['yanzheng']){
		 
		   $ajax=3;$this->ajaxReturn($ajax);
		 
		 }
		 
		 if($_POST['yanzheng']==""){
		 
		    $ajax=3;$this->ajaxReturn($ajax);
		 
		 }
	
	
	     $arr['tixianid']=$_POST['id'];
		 
		 $arr['money']=$_POST['money'];
		 
		 $arr['type']=1;
		 
		 $arr['time']=time();
		 
		 $arr['status']=1;
		 
		 
		 $re=M('tixian')->add($arr);
		 
		 $user=M('dailiuser')->where('id="%s"',$_POST['id'])->find();
		 
		 $u['money']=$user['money']-$_POST['money'];
		 
		 M('dailiuser')->where('id="%s"',$_POST['id'])->save($u);
		 
		 
	      if($re){
		  
		  $ajax=1;
		  
		  }else{
		  
		  
		    $ajax=2;
		  }
	
	     $this->ajaxReturn($ajax);
	}
	
	
	
	public function xiugai(){
	
	    $result=M('yanzheng')->where('id=1')->find();
	
	     if($result['yanzheng']!=$_POST['yanzheng']){
		 
		   $ajax=3;$this->ajaxReturn($ajax);
		 
		 }
		 
		 if($_POST['yanzheng']==""){
		 
		    $ajax=3;$this->ajaxReturn($ajax);
		 
		 }
	
	
	    $re=M('dailiuser')->save($_POST);
		
		if($re!==false){
		
		
		  $ajax=1;
		}else{
		
		  $ajax=2;
		
		}
		
	
	    $this->ajaxReturn($ajax);
	
	}
	
  
  
  }